package com.ccc.dingtalk.controller;

import com.ccc.dingtalk.response.ResponseCode;
import com.ccc.dingtalk.response.ResponseResult;
import com.ccc.dingtalk.service.dingtalk.AttendanceService;
import com.ccc.dingtalk.service.dingtalk.ClockService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 首页控制器
 *
 * @author superC
 * @version 1.0.0
 * @date 2023-08-08
 */

@RestController
@RequestMapping("/home")
public class HomeController {
    protected static final Logger logger = LoggerFactory.getLogger(HomeController.class);

    @Autowired
    private AttendanceService attendanceService;

    @Autowired
    private ClockService clockService;

    /**
     * 获取今天所有员工的考勤打卡列表
     *
     * @return
     */
    @GetMapping("/getTodayClockList")
    public ResponseResult getTodayClockList() {
        try {
            // 获取全部员工查询
            return ResponseResult.success("获取数据成功", attendanceService.getTodayAttendanceList2AllUser());
        } catch (Exception e) {
            logger.error("【捕获异常-获取今天所有员工的考勤打卡列表】\r\n异常记录：", e);
            return ResponseResult.failure(ResponseCode.DATA_GET_ERROR, e.getMessage());
        }
    }

    /**
     * 获取钉钉的考勤打卡时间
     *
     * @return
     */
    @GetMapping("/getClockTime")
    public ResponseResult getClockTime() {
        try {
            return ResponseResult.success("获取数据成功", clockService.getClockTime());
        } catch (Exception e) {
            logger.error("【捕获异常-获取钉钉的考勤打卡时间】\r\n异常记录：", e);
            return ResponseResult.failure(ResponseCode.DATA_GET_ERROR, e.getMessage());
        }
    }

}
